const mysql = require('mysql')
const { database, user, password } = require('../config')

const pool = mysql.createPool({
  database,
  user,
  password
})

const postQuery = (sql) => {
  return new Promise((resolve, reject) => {
    pool.getConnection((err, connection) => {
      if (err) return reject(err);
      connection.query(sql, (err,data) => {
        connection.release();
        if (err) return reject(err);
        resolve(data);
      });
    })
  })
}

module.exports = {
  postQuery
}
